#include"boiteDialog.h"
#include<QHeaderView>
#include<iostream>
BoiteDialog::BoiteDialog(Fenetre *parent, Qt::WindowFlags f): QDialog(parent, f)
{
    parent_ = parent;
    layoutDialog_ = new QHBoxLayout(this);
    /*definition des modeles d'affichage*/
        models_[MODELTYPE_ETUDIANT] = new QStandardItemModel();
        models_[MODELTYPE_ENSEIGNANT] = new QStandardItemModel();
        models_[MODELTYPE_SALLE] = new QStandardItemModel();
        models_[MODELTYPE_MODULE] = new QStandardItemModel();
        models_[MODELTYPE_GROUPE] = new QStandardItemModel();
        models_[MODELTYPE_CRENEAU] = new QStandardItemModel();

        /*definition du modele d'affichage pour le calcul de la taille de la fenetre*/
    modelModif_ = models_[MODELTYPE_MODULE];

    treeModif_ = new QTreeView(this);
    treeModif_->setModel(modelModif_);

    /*ajout du modele au conteneur principal*/
    layoutDialog_->addWidget(treeModif_);
    /*definition du modele d'affichage*/
    modelModif_ = models_[MODELTYPE_ETUDIANT];
    treeModif_->setModel(modelModif_);
    treeModif_->header()->hide();

    connect(treeModif_,
            SIGNAL(expanded(QModelIndex)),
            parent_,
            SLOT(getData(QModelIndex)));

    connect(treeModif_,
            SIGNAL(collapsed(QModelIndex)),
            parent_,
            SLOT(setCreate(QModelIndex)));

    connect(this,
            SIGNAL(rejected()),
            this,
            SLOT(changeBoutonModif()));
}

void BoiteDialog::changeTab(int i)
{
    modelModif_ = models_[i];
    treeModif_->setModel(modelModif_);
}

void BoiteDialog::changeBoutonModif()
{
    parent_->getBoutonModif()->setMirrored(false);
    parent_->getBoutonModif()->setChecked(false);
}

QStandardItemModel* BoiteDialog::getModel(const int &index)
{
    return models_[index];
}


QTreeView* BoiteDialog::getTreeModif()
{
    return treeModif_;
}

DialogAjout::DialogAjout(Fenetre *parent, Qt::WindowFlags f): QDialog(parent, f)
{

    parent_ = parent;

    typeModel_ = 0;

    layoutDialog_ = new QVBoxLayout();


    modele_ = new QStringListModel();

    viewList_ = new QListView(this);
    layoutDialog_->addWidget(viewList_);

    setLayout(layoutDialog_);

}

void DialogAjout::setModel(const QStringList list)
{
    modele_->setStringList(list);
    viewList_->setModel(modele_);
}

void DialogAjout::setTypeModel(const int &i)
{
    typeModel_ = i;
}

int DialogAjout::getTypeModel() const
{
    return typeModel_;
}

QListView* DialogAjout::getViewList() const
{
    return viewList_;
}

